<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('组装单')" />
	<th:block th:include="include :: businessCSS" />
    <style>
        .layui-table-tool{display: none;}
    </style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="north">
            <!-- <th:block th:include="include :: business_btn" /> -->
	        <th:block th:include="include :: business_tpl('top')" />
    	</div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	   	<!-- <th:block th:include="include :: pageFooter" />  -->
        <div th:if="${enableEdit==1}" style="position: fixed;bottom: 0;z-index: 99;text-align:center;background: #fff;width: 100%;">
            <input type="button" style="position:relative;top: -20px;width: 100px;background: rgb(0, 135, 250);padding: 7px;color: #fff;border: none;border-radius: 10px;cursor: pointe" lay-submit lay-filter="btn-add" id="btn-add" value="保存">
            <!-- <button class="layui-btn layui-btn-normal" lay-submit style="position:relative;top: -20px;width: 100px;" lay-filter="btn-add">保存</button> -->
            <!-- <span style="display: inline-block;background: rgb(0, 135, 250);padding: 5px;color: #fff;position: relative;top: -20px;width: 100px;border-radius: 10px;cursor: pointer;">保存</span> -->
        </div>
        </form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />
<script th:inline="javascript">
    var enableEdit = [[${enableEdit}]]

</script>
<script type="text/javascript">
var $,layer,form,table,laydate,element;//定义layui模块
eachFields();//明细表格中的字段遍历
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get("/storage/productassemble/listbynid?nid="+nid,function(data){
		$.each(data.data,function(k,v){
			dataStr.push(v);
		});
		initTable();//初始化表格
	});


	$('body').on('blur','#actualNum',function(){
		var num=+$(this).val()
		var dataArr=table.cache["dhtable"]
		dataArr.map((v)=>{
            v.sonBalance=+v.sonNum-(+v.vBz*num)
            v.sonUseTotal=+v.vBz*num
		})
		table.reload('dhtable', {data: dataArr});
	})

	toolbarEvent();//通用表格头部工具栏事件监听
	toolEvent('ftable');//行event事件监听
	monitorSort();//监听排序——重载赋值渲染
	moneyCalculation();//表格编辑——资金计算

	if (enableEdit){
		$("#actualNum").removeClass("canntEdit").removeAttr("readonly")
		$("#vZdbz").removeClass("canntEdit").removeAttr("readonly")//特定字段可编辑
		var dataArr=gridColumns.gridBody
		$.each(dataArr, function (i, v) {
			if (v.field==='sonActualBalance'){
				v.edit = "text";
			}else{
				// v.style("background-color: rgb(242 242 242)")
				v.style= "background-color: #f2f2f2"
				delete v['templet']
			}
			if (i === 19){
			}
		})//移除表格编辑属性
	}


	form.on('submit(btn-add)', function(data){
		if(parseInt(data.field.actualNum) > parseInt(data.field.planNum)) {
			layer.confirm('实际组装数量大于计划数量，确定保存？', {icon: 3, title:'提示'}, function(index){

		        $.operate.post("/storage/productassemble/editpost",{'infoItems':JSON.stringify(table.cache.dhtable),infoMap:JSON.stringify(data.field)},function(res){
		            layer.msg(res.msg)
		            if(res.code==0){
		                setTimeout(function(){
		                    window.location.href = "/storage/productassemble/edit?nid="+res.data;
		                }, 1000);
		            }
		        })
			});
		} else {
	        $.operate.post("/storage/productassemble/editpost",{'infoItems':JSON.stringify(table.cache.dhtable),infoMap:JSON.stringify(data.field)},function(res){
	            layer.msg(res.msg)
	            if(res.code==0){
	                setTimeout(function(){
	                    window.location.href = "/storage/productassemble/edit?nid="+res.data;
	                }, 1000);
	            }
	        })
		}
		return;
    })
})
</script>
</body>
</html>